<template>
	<view class="decision-app-box">
		<u-tabs
			height="60"
			:list="list"
			:show-bar="false"
			font-size="26"
			:bold="false"
			:is-scroll="false"
			:current="current"
			@change="changeTabs"
			class="tabs-border"
		></u-tabs>

		<view class="decision-app-box-content">
			<sjsb v-if="cardCur == 'sjsb'"></sjsb>
			<report v-if="cardCur == 'report'" @getNum="getNum"></report>
			<reportToMe v-if="cardCur == 'reportToMe'"></reportToMe>
			<message v-if="cardCur == 'message'"></message>
		</view>
	</view>
</template>

<script>
	import sjsbApi from '@/api/yjzh/sjsb.js'
	import moment from 'moment'
	export default {
		components: {
			sjsb: () => import('./events/sjsb.vue'),
			report: () => import('./events/report.vue'),
			message: () => import('./events/message.vue'),
			reportToMe: () => import('./events/reportToMe.vue')
		},
		data() {
			return {
				cardCur: 'sjsb',
				current: 0,
				list: [
					{ name: '事件上报', value: 'sjsb' },
					{ name: '我的报告', value: 'report', count: 0 },
					{ name: '报给我的', value: 'reportToMe', count: 0 },
					{ name: '事件信息', value: 'message' }
				]
			}
		},
		onShow() {},
		async mounted() {
			this.init()
			uni.$on('eventPage', (data) => {
				this.setTab(data.page)
			})
		},
		computed: {},

		methods: {
			setTab(tabValue) {
				this.current = this.list.findIndex((el) => el.value == tabValue)
				this.cardCur = tabValue
			},
			changeTabs(index) {
				this.current = index
				this.cardCur = this.list[index].value
			},
			async init() {
				const userInfo = uni.getStorageSync('userInfo')
				const resp = await sjsbApi.reportEvent({
					areaCode: this.UserInfoData.dept.code
				})
				this.list[2].count = resp.data.length
				// 判断乡镇用户
				if (this.UserInfoData.dept.parentCode && this.UserInfoData.dept.parentCode != '350400000000') {
					this.list.splice(2, 1)
				}

				const myNum = await sjsbApi.myEventResultList({
					userId: userInfo.user_id,
					date: moment().format('YYYY-MM-DD HH:mm:ss') // this.form.time,
				})
				console.info(`myNum:`, myNum)
				let myNumList = myNum.data.filter((el) => {
					return el.status == 1
				})
				this.list[1].count = myNumList.length
			},
			getNum(value) {
				this.list[1].count = value
			}
		},
		beforeDestroy() {
			uni.$off('eventPage')
		}
	}
</script>

<style lang="scss" scoped>
	.decision-app-box {
		height: 100%;
		background: #fff;
		.tabs-border {
			border-bottom: 0.5rpx solid rgba(0, 0, 0, 0.061);
			padding: 0 20rpx;
		}
		.decision-app-box-content {
			height: calc(100% - 60rpx);
		}
	}
</style>
